#!/bin/bash
#
# REQUIRES:
# 	- __promoteUser.sh
#	- createEmptyPkgWithScript.sh
#
# Accepts a username as the only argument and generates a package, as well as 
# an uninstaller that will make that user account administrative on the target
# computer. The uninstall method obviously removes those admin privileges.
#

username="${1}"

while [ -z "${username}" ]; do
	echo -n "Enter the username to add to the admin group: "
	read username
done


BASE_DIR=`dirname "${0}"`

script="${BASE_DIR}/admin-rights-for_${username}"
cat "${BASE_DIR}/__promoteUser.sh" | sed "s/some.user/${username}/" > "${script}"

chmod a+x "${script}"
sh "${BASE_DIR}/createEmptyPkgWithScript.sh" "${script}" "1.0" "production" "settings/admins"
rm "${script}"
munkiDir=`dirname "${BASE_NAME}"`
/usr/libexec/PlistBuddy \
	"${munkiDir}/pkgsinfo/settings/admins/admin-rights-for_${username}-1.0" \
	-c "Set uninstall_method /Library/Scripts/Administrative-Rights/remove-admin-rights_${username}.sh"

/usr/local/munki/makecatalogs
echo ""
echo ""
